package com.baway.empty;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.net.HttpURLConnection;
import java.net.Socket;

import okhttp3.OkHttpClient;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okio.ByteString;

/**
 * Author: Jason Zhang
 * Date: 2025/9/1
 * Desc:
 */
public class TestDemo {

    public static void main(String[] args) {

        OkHttpClient client = new OkHttpClient.Builder().build();

        client.newWebSocket(null, new WebSocketListener() {

            /**
             * 连接已经关闭
             * @param webSocket
             * @param code
             * @param reason
             */
            @Override
            public void onClosed(@NonNull WebSocket webSocket, int code, @NonNull String reason) {
                super.onClosed(webSocket, code, reason);
            }

            /**
             * 连接关闭中
             * @param webSocket
             * @param code
             * @param reason
             */
            @Override
            public void onClosing(@NonNull WebSocket webSocket, int code, @NonNull String reason) {
                super.onClosing(webSocket, code, reason);
            }

            /**
             * 连接报错
             * @param webSocket
             * @param t
             * @param response
             */
            @Override
            public void onFailure(@NonNull WebSocket webSocket, @NonNull Throwable t, @Nullable Response response) {
                super.onFailure(webSocket, t, response);
            }

            /**
             * 接收到纯文本数据
             * @param webSocket
             * @param text
             */
            @Override
            public void onMessage(@NonNull WebSocket webSocket, @NonNull String text) {
                super.onMessage(webSocket, text);
            }

            /**
             * 接收字节串数据
             * @param webSocket
             * @param bytes
             */
            @Override
            public void onMessage(@NonNull WebSocket webSocket, @NonNull ByteString bytes) {
                super.onMessage(webSocket, bytes);
            }

            /**
             * 连接成功
             * @param webSocket
             * @param response
             */
            @Override
            public void onOpen(@NonNull WebSocket webSocket, @NonNull Response response) {
                super.onOpen(webSocket, response);
            }
        });
    }


    private void javaSocket(){



    }

}
